Skip to content

Project class interface #511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 29, 2024
Merged

Project class interface #511

merged 13 commits into from
Oct 29, 2024

Conversation

andrzej-krupka
Copy link
Contributor

No description provided.

@andrzej-krupka andrzej-krupka marked this pull request as draft October 24, 2024 12:31
@andrzej-krupka andrzej-krupka force-pushed the andrzej/project-class branch 7 times, most recently from 2fe2045 to 9b86c19 Compare October 24, 2024 17:05
@andrzej-krupka andrzej-krupka marked this pull request as ready for review October 24, 2024 17:20
@andrzej-krupka andrzej-krupka force-pushed the andrzej/project-class branch 2 times, most recently from ee4bf29 to 723158c Compare October 24, 2024 18:08
params = SimulationParams(
operating_condition=AerospaceCondition(velocity_magnitude=100 * u.m / u.s),
models=[
Fluid(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fluid will be added automatically, remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ba5587


fl.Env.dev.active()

SOLVER_VERSION = "workbench-24.9.3"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's be consistent with solver version. Let's always use release-24.11

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ba5587

project = Project.from_file(
OM6wing.mesh_filename,
name="wing-volume-mesh-python-upload",
solver_version="workbench-24.9.3",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add repository-level default solver version

Copy link
Contributor Author

@andrzej-krupka andrzej-krupka Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ba5587, added __solver_version__ to version.py

except Flow360FileError:
pass
raise Flow360FileError(
f"{file} is not a geometry or volume mesh file required for project initialization."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in error message, list what file extension is expected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ba5587

Comment on lines 218 to 224
def from_file(
cls,
file: str = None,
name: str = None,
solver_version: str = None,
length_unit: LengthUnitType = "m",
tags: List[str] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use pydantic's "validate_call" decorator to validate inputs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ba5587, added validate_call where applicable in other user-facing methods

"Project is not initialized - use Project.from_file or Project.from_cloud"
)

def get_simulation_json(self) -> dict:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_simulation_json(self) -> dict:
def get_root_simulation_json(self) -> dict:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ba5587

Comment on lines 354 to 357
if root_type == RootType.GEOMETRY:
root_api = RestApi(GeometryInterface.endpoint, id=root_id)
elif root_type == RootType.VOLUME_MESH:
root_api = RestApi(VolumeMeshInterfaceV2.endpoint, id=root_id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do it in constructors init_webapi ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ba5587

root_api = RestApi(VolumeMeshInterfaceV2.endpoint, id=root_id)
resp = root_api.get(method="simulation/file", params={"type": "simulation"})
if not isinstance(resp, dict) or "simulationJson" not in resp:
raise Flow360WebError("Root item type or ID is missing from project metadata")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the message seems be incorrect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ba5587

Comment on lines 439 to 443
for _, old_entity in enumerate(old_draft_entities):
try:
registry.find_by_naming_pattern(old_entity.name)
except ValueError:
continue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand intention of this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pasted over from the previous cloud class but you're right - this looks like it has no effect. I'll double-check with Ben.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ba5587, but might need another small change, see DM on Slack

Comment on lines 451 to 456
RestApi(ProjectInterface.endpoint, id=self.metadata.id).patch(
json={
"lastOpenItemId": destination_id,
"lastOpenItemType": target.__name__,
}
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialise this in constructor and run:

Suggested change
RestApi(ProjectInterface.endpoint, id=self.metadata.id).patch(
json={
"lastOpenItemId": destination_id,
"lastOpenItemType": target.__name__,
}
)
self.webapi.patch(
json={
"lastOpenItemId": destination_id,
"lastOpenItemType": target.__name__,
}
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ba5587

Whether to fork the case (default is True).
"""
self._check_initialized()
self._case = self._run(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if a user runs a batch of cases by tweaking parameter? Then _case will get overwritten every time a new case is submitted? Can we instead create a draft_name (which IIRC is the case/VM/SM name) to asset(or just asset ID) map instead? @maciej-flexcompute what do you think?

Copy link
Contributor Author

@andrzej-krupka andrzej-krupka Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I was initially under the impression that these properties will hold the most recently opened assets (geometry, surface mesh, volume mesh, case) but in case of batch runs we should probably keep some history of all loaded asset objects... Maybe we could have a history interface of sorts where the user can see previous assets?

Something like

for i in range(0, 50):
    project.run_case(...)

# Show most recent one
case = project.case

# Show history of all project runs
for id in project.case_history():
    # Load the project with a specified ID
    case = project.case(id)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. We need to fix this though since I expect the major use for python client is batch submission.

Another simple way is to just return the Case obj and ask user to manage their cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this interface in 3b7aa70, check project_from_file_geometry_multiple_runs.py for reference.

@andrzej-krupka andrzej-krupka force-pushed the andrzej/project-class branch 2 times, most recently from 71a5c39 to 2939dfa Compare October 28, 2024 14:29
@maciej-flexcompute maciej-flexcompute merged commit ceb43dc into develop Oct 29, 2024
12 checks passed
@maciej-flexcompute maciej-flexcompute deleted the andrzej/project-class branch October 29, 2024 17:31
benflexcompute added a commit that referenced this pull request Oct 29, 2024
* Added initial version of the Project class interface

* Added examples, remove usages of cloud static functions

* Entity info injection during _run()

* Style fixes

* Fix webapi test

* Fix examples, fix from_cloud

* Add case fork option

* Switched docstrings to numpy style

* Fix PR feedback

* Fix PR feedback #2

* Fix PR feedback #3

* Fix PR feedback #4

---------

Co-authored-by: Ben <106089368+benflexcompute@users.noreply.github.com>
maciej-flexcompute pushed a commit that referenced this pull request Oct 29, 2024
* Added initial version of the Project class interface

* Added examples, remove usages of cloud static functions

* Entity info injection during _run()

* Style fixes

* Fix webapi test

* Fix examples, fix from_cloud

* Add case fork option

* Switched docstrings to numpy style

* Fix PR feedback

* Fix PR feedback #2

* Fix PR feedback #3

* Fix PR feedback #4

---------

Co-authored-by: andrzej-krupka <156919532+andrzej-krupka@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants